import axios from '@/utils/request';
const baseOriginURL = process.env.VUE_APP_BASE_ORIGIN + '/iot_service';
const baseRoleURL = process.env.VUE_APP_BASE_ORIGIN + '/iot_system';
const baseAuthURL = process.env.VUE_APP_BASE_ORIGIN + '/iot_common';

// 应用列表
const serviceList = () => {
  return axios.get(baseOriginURL + '/service/list');
};

/*************** PC权限接口 *****************/
// 获取权限配置
const authorityList = () => {
  return axios.get(baseRoleURL + '/role/getAuthList');
};

// 创建权限配置
const createAuthority = data => {
  return axios.post(baseRoleURL + '/role/createAuthNode', data);
};

// 修改权限配置
const updateAuthority = data => {
  return axios.put(baseRoleURL + '/role/updateAuthNode', data);
};

// 新建功能
const createButton = data => {
  return axios.post(baseRoleURL + '/role/createButton', data);
};

// 新建功能页面
const createSubPackage = data => {
  return axios.post(baseRoleURL + '/role/createSubPackage', data);
};

// 修改功能
const updateButton = data => {
  return axios.put(baseRoleURL + '/role/updateButton', data);
};

// 修改功能页面
const updateSubPackage = data => {
  return axios.put(baseRoleURL + '/role/updateSubPackage', data);
};

// 删除
const deleteAuthNode = data => {
  return axios.delete(baseRoleURL + '/role/deleteAuthNode', data);
};

// 修改菜单顺序
const setAuthSort = data => {
  return axios.put(baseRoleURL + '/role/setAuthSort', data);
};

/*************** APP权限接口 *****************/
// 获取app权限列表
const getAppAuthNodeList = () => {
  return axios.get(baseRoleURL + '/role/getAppAuthNodeList');
};

// 创建app权限节点
const createAppAuthNode = data => {
  return axios.post(baseRoleURL + '/role/createAppAuthNode', data);
};

// 修改app权限节点
const updateAppAuthNode = data => {
  return axios.put(baseRoleURL + '/role/updateAppAuthNode', data);
};

// 删除app权限节点
const deleteAppAuthNode = data => {
  return axios.delete(baseRoleURL + '/role/deleteAppAuthNode', data);
};

// 获取公司app权限列表
const getCustomerRolePowerForApp = () => {
  return axios.get(baseRoleURL + '/role/getCustomerRolePowerForApp');
};

// 获取角色app权限列表
const getUserRolePowerForApp = () => {
  return axios.get(baseAuthURL + '/auth/getUserRolePowerForApp');
};

// 通过应用ID获取权限
const getAuthByServerId = params => {
  return axios.get(baseAuthURL + '/auth/getAuthByServerId', {
    params
  });
};

// 通过菜单ID获取权限
const getAuthByMenuId = params => {
  return axios.get(baseAuthURL + '/auth/getAuthByMenuId', {
    params
  });
};

export {
  serviceList,
  authorityList,
  createAuthority,
  updateAuthority,
  createButton,
  createSubPackage,
  updateButton,
  updateSubPackage,
  deleteAuthNode,
  setAuthSort,
  getAppAuthNodeList,
  createAppAuthNode,
  updateAppAuthNode,
  deleteAppAuthNode,
  getCustomerRolePowerForApp,
  getUserRolePowerForApp,
  getAuthByServerId,
  getAuthByMenuId
};
